#include <cstdio>

int judge(int year, int month) {
	if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
		return 1; //31
	else if(month==2) {
		if(year%4!=0 || year%10==4 && year%400!=0)
			return 2; // 平年
		else
			return 3; //润年
	}
	else
		return 4;
}

int main(int argc, char * argv[]) {
	int year, i, j, a, n, m, k;
	char ** p;
	char * week[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
	char * month[] = {"January", "February", "March", "April", "May", "June",
		"July", "August", "September", "October", "November", "December"
	};

	// clrscr();
	printf("Please Enter the year: ");
	scanf("%d", &year);
	printf("\n");
	printf("The calendar of the year %d.\n", year);

	// 判断这一年的第一天是星期几
	a = (year + (year-1)/4 - (year-1)/100 + (year-1)/400) % 7;
	for(i=0; i<12; i++) {
		n = judge(year, i+1);
		p = month + i;
		printf("%s\n", *p);
		printf("\n");

		for(j=0; j<7; j++) {
			p = week + j;
			printf("%6s", *p);
		}
		printf("\n");
		for(k=0; k<a; k++)
			printf("      ");
		for(m=1; m<32; m++) {
			printf("%6d", m);
			if((a+m)%7 == 0)
				printf("\n");
			if(n==1 && m==31)
				break;
			else if(n==2 && m==28)
				break;
			else if(n==3 && m==29)
				break;
			else if(n==4 && m==30)
				break;
		}
			
			a = (a+m) % 7;
			printf("\n");
			printf("============================================");
			printf("\n");

	}
	
	return 0;
}
